<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2022/8/14
  Time: 18:16
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
</head>
<body>
<h3 style="margin-left: 111px">新增图书信息</h3>
<form action="BookManageAdd" method="post">
    图书名称：<input type="text" id="name" name="name"><br>
    图书作者：<input type="text" id="author" name="author"><br>
    购买日期：<input type="text" id="time" name="time"> <span>yyyy-MM-dd格式</span><br>
    图书类别：
    <select name="type" id="type">
        <option selected value="0">选择所属分类</option>
        <option value="1">计算机/软件</option>
        <option value="2">小说/文摘</option>
        <option value="3">杂项</option>
    </select><br>
    <input style="margin-left: 120px" type="submit" value="增加图书">
</form>
<script src="jq/jquery.js"></script>
<script>
    $('form').submit(function () {
        var flag = false;
        if(!CheckName()) return false;
        else if(!CheckAuthor()) return false;
        else if(!CheckTime()) return false;
        else if(!CheckType()) return false;
        return true;
    })

    function CheckName(){
        if($('#name').val()==""){
            alert('图书名称和作者姓名不能为空');
            return false;
        }
        return true;
    }

    function CheckAuthor() {
        if($('#author').val()==""){
            alert('图书名称和作者姓名不能为空');
            return false;
        }
        return true;
    }

    function CheckTime() {
        if(/^(\d{4})-(\d{2})-(\d{2})$/.test($('#time').val())==false){
            alert('日期格式错误');
            return false;
        }
        return true;
    }

    function CheckType() {
        if($('#type').val()==0){
            alert('请选择图书分类');
            return false;
        }
        return true;
    }
</script>
</body>
</html>
